package service

// 0-999 号段用于sase自定义通用响应
// 0-100 号段用于错误码通用描述，(例如: 请求成功、请求失败、认证成功、认证失败)
// 100-999 号段用于错误码详细描述，（例如: token请求成功、token请求失败、证书过期认证失败、证书不合法认证失败）
const (
	StatusOK      = 0
	StatusFailure = 1
	StatusUnknown = 2

	StatusBadRequest      = 10
	StatusUnauthorized    = 11
	StatusForbidden       = 12
	StatusNotFound        = 13
	StatusTooManyRequests = 14

	StatusInvalidRequestParameter = 15

	StatusInternalServerError = 20
	StatusServiceUnavailable  = 21
	StatusDeadline            = 22

	// 100-119 证书
	StatusCertificateInvalid      = 100
	StatusCertificateNotSupported = 101
	StatusCertificateUnverified   = 102
	StatusCertificateMissing      = 103
	StatusCertificateMismatch     = 104

	// 120-139 token
	StatusTokenExpired            = 121
	StatusTokenInvalid            = 122
	StatusTokenNotExist           = 123
	StatusTokenGenerationFailed   = 124
	StatusTokenFormatNotSupported = 125
)

var statusText = map[int]string{
	StatusOK:      "成功",
	StatusFailure: "失败",
	StatusUnknown: "未知错误",

	StatusBadRequest:      "请求参数无法解析",
	StatusUnauthorized:    "未提供身份验证凭据或身份验证失败",
	StatusForbidden:       "经过身份验证,用户无权访问",
	StatusNotFound:        "未找到资源",
	StatusTooManyRequests: "请求太过频繁",

	StatusInvalidRequestParameter: "请求参数非法",

	StatusInternalServerError: "内部服务错误",
	StatusServiceUnavailable:  "过载保护,服务暂不可用",
	StatusDeadline:            "服务调用超时",

	StatusCertificateInvalid:      "证书不合法",
	StatusCertificateNotSupported: "证书类型不支持",
	StatusCertificateUnverified:   "证书校验未通过",
	StatusCertificateMissing:      "证书缺失",
	StatusCertificateMismatch:     "证书不匹配",

	StatusTokenExpired:            "token已过期",
	StatusTokenInvalid:            "token无效",
	StatusTokenNotExist:           "token不存在",
	StatusTokenGenerationFailed:   "token创建失败",
	StatusTokenFormatNotSupported: "token请求方式有误",
}

func StatusText(code int) string {
	return statusText[code]
}
